#[cfg(test)]
mod tests {
    #[test]
    #[should_panic(expected = "cannot assign")]
    fn test_immutable_borrow() {
        let mut x = 5;
        let y = &x;
        x = 10; // 应该触发编译错误（测试运行时错误）
        assert_eq!(*y, 5);
    }

    #[test]
    fn test_mutable_borrow() {
        let mut s = String::from("hello");
        let r1 = &mut s;
        r1.push_str(" world");
        assert_eq!(s, "hello world");
    }

    #[test]
    fn test_lifetime() {
        fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
            if x.len() > y.len() {
                x
            } else {
                y
            }
        }
        let string1 = String::from("long string is long");
        let result;
        {
            let string2 = String::from("xyz");
            result = longest(string1.as_str(), string2.as_str());
        }
        assert_eq!(result, "long string is long");
    }
}